from mcp.server.fastmcp import FastMCP
import asyncio

# 创建服务器实例
mcp = FastMCP(
    name="Resource Server",
    version="1.0.0"
)

@mcp.resource("http://localhost:8000/users")
async def get_user_resource():
    """获取用户资源"""
    # 模拟异步操作
    await asyncio.sleep(0.1)
    return {
        "user_id": "001",
        "name": f"User 001",
        "created_at": "2024-01-01"
    }

@mcp.resource("config://app/{config_section}")
def get_app_config(config_section: str):
    """获取应用配置"""
    configs = {
        "database": {
            "host": "localhost",
            "port": 5432,
            "dbname": "myapp"
        },
        "cache": {
            "redis_host": "localhost",
            "redis_port": 6379
        },
        "api": {
            "timeout": 30,
            "retries": 3
        }
    }
    return configs.get(config_section, {})

if __name__ == "__main__":
    # 运行服务器
    mcp.run(transport="sse")